Skip to content

test(coverage): worker logsafe/migrations/root ≥95%#56

Merged
mastermanas805 merged 1 commit into
masterfrom
coverage/worker-logsafe-mig-root-95
May 22, 2026
Merged

test(coverage): worker logsafe/migrations/root ≥95%#56
mastermanas805 merged 1 commit into
masterfrom
coverage/worker-logsafe-mig-root-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

Closes three code-coverage gaps in the worker repo, driving each target area to 100% (well above the 95% floor), using test seams not waivers.

Coverage block (before → after)

Area Before After
internal/logsafe 88.9% 100.0%
internal/migrations 93.9% 100.0%
root pkg instant.dev/worker (main.go) 0% 100.0%
cmd/smoke-buildinfo (bonus) 0% 50.0%

Measured by full-suite go test ./... -short. Full suite passes; all other packages unchanged.

What changed

internal/logsafe (88.9 → 100): added a direct unit test for the unexported itoa helper covering the n==0 and defensive n<0 branches that Token() can't reach via a real len() argument.

internal/migrations (93.9 → 100): added tests for NewReader's ttl<=0 default-clamp branch (behavioural — verifies the cache TTL is positive) and queryState's COUNT-query error path (sqlmock). No DB required — the package already uses go-sqlmock.

root main.go (0 → 100): the binary's main() was one large untestable function. Refactored using the standard Go main-coverage seam:

  • Extracted pure/wiring helpers: setupLogger, resolvePlansPath, loadPlanRegistry, newHealthzHandler, buildMux, serveLiveness/startLivenessServer/shutdownLivenessServer, awaitShutdown, setupTelemetry/telemetryCleanup, connectProvisioner, deployK8sInitOK, newSignalContext.
  • Introduced a run(ctx, deps) int seam where infra constructors are injectable (deps struct) plus package-var indirection (osExit, signalCtxFn, realMainFn, newDeployK8sClients).
  • main() is now a thin osExit(realMainFn(...)) wrapper, itself covered by swapping its indirected collaborators.
  • Tests drive the full boot/clean-shutdown and River-failed-to-start paths with sqlmock + miniredis + a fake workerSet + a cancelled context — no real Postgres / Redis / gRPC / River. A generic forceErr3 wrapper exercises the fail-open k8s-init branch without naming the unexported provider types.

cmd/smoke-buildinfo (bonus): extracted a render(io.Writer) seam (100% covered); the remaining main() is the irreducible one-line wrapper.

Verification

  • go build ./... clean
  • go vet ./... clean
  • target packages pass under -race
  • full-suite go test ./... -short green

🤖 Generated with Claude Code

Drive three coverage gaps to ≥95% (all hit 100%) via test seams, no waivers:

- internal/logsafe (88.9% → 100%): cover itoa's n==0 and defensive n<0
  branches with a direct unit test.
- internal/migrations (93.9% → 100%): cover NewReader's ttl<=0 default-clamp
  branch and queryState's COUNT-query error path with sqlmock.
- root package main.go (0% → 100%): introduce a run(ctx, deps) seam plus
  realMain/main wrapper indirection. Extract setupLogger, resolvePlansPath,
  loadPlanRegistry, newHealthzHandler, buildMux, serveLiveness/
  startLivenessServer/shutdownLivenessServer, awaitShutdown, setupTelemetry/
  telemetryCleanup, connectProvisioner, deployK8sInitOK, prodStartWorkers,
  newSignalContext. Inject infra constructors (deps struct + package vars
  osExit/signalCtxFn/realMainFn/newDeployK8sClients) so the full boot/shutdown
  path is exercised with sqlmock + miniredis + a fake workerSet and a
  cancelled context — no real Postgres/Redis/gRPC/River.
- cmd/smoke-buildinfo (0% → 50%): extract render(io.Writer) seam + test;
  main() is the irreducible one-line wrapper.

Full suite `go test ./...` builds; target packages pass under -race;
go build ./... && go vet ./... clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805 mastermanas805 merged commit abe261c into master May 22, 2026
8 of 10 checks passed
@mastermanas805 mastermanas805 deleted the coverage/worker-logsafe-mig-root-95 branch May 22, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant